package nl.jworks.epuborganizer.client.main;


/**
 * Sencha GXT 3.0.1 - Sencha for GWT
 * Copyright(c) 2007-2012, Sencha, Inc.
 * licensing@sencha.com
 *
 * http://www.sencha.com/products/gxt/license/
 */

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.*;
import com.sencha.gxt.core.client.Style.LayoutRegion;
import com.sencha.gxt.core.client.util.Margins;
import com.sencha.gxt.widget.core.client.Component;
import com.sencha.gxt.widget.core.client.ContentPanel;
import com.sencha.gxt.widget.core.client.button.TextButton;
import com.sencha.gxt.widget.core.client.container.BorderLayoutContainer;
import com.sencha.gxt.widget.core.client.container.BorderLayoutContainer.BorderLayoutData;
import com.sencha.gxt.widget.core.client.container.MarginData;
import com.sencha.gxt.widget.core.client.container.Viewport;
import com.sencha.gxt.widget.core.client.event.SelectEvent;
import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
import com.sencha.gxt.widget.core.client.info.Info;
import nl.jworks.epuborganizer.client.GreetingService;
import nl.jworks.epuborganizer.client.GreetingServiceAsync;
import nl.jworks.epuborganizer.client.accordion.AccordionUiBinderExample;
import nl.jworks.epuborganizer.client.tabs.BasicTabUiBinderExample;

public class MainScreen implements IsWidget, EntryPoint {

    interface MyUiBinder extends UiBinder<Component, MainScreen> {
    }

    private static MyUiBinder uiBinder = GWT.create(MyUiBinder.class);

    @UiField(provided = true)
    String txt = "Test 2";


    @UiField(provided = true)
    MarginData outerData = new MarginData(0);
    @UiField(provided = true)
    BorderLayoutData northData = new BorderLayoutData(100);
    @UiField(provided = true)
    BorderLayoutData westData = new BorderLayoutData(150);
    @UiField(provided = true)
    MarginData centerData = new MarginData();
    @UiField(provided = true)
    BorderLayoutData eastData = new BorderLayoutData(150);
    @UiField(provided = true)
    BorderLayoutData southData = new BorderLayoutData(100);

    @UiField(provided = true)
    ContentPanel west = new ContentPanel();

    @UiField
    BorderLayoutContainer con;

    @UiField(provided = true)
    ContentPanel center = new ContentPanel();

    public Widget asWidget() {
        northData.setMargins(new Margins(5));
        northData.setSize(20);
        westData.setMargins(new Margins(0, 5, 0, 5));
        westData.setCollapsible(true);
        westData.setSplit(true);
        eastData.setMargins(new Margins(0, 5, 0, 5));
        southData.setMargins(new Margins(5));

        west.add(new AccordionUiBinderExample());
        center.add(new BasicTabUiBinderExample());

        Widget widget = uiBinder.createAndBindUi(this);

        for (int i = 0; i < LayoutRegion.values().length; i++) {
            final LayoutRegion r = LayoutRegion.values()[i];
            if (r == LayoutRegion.CENTER) {
                continue;
            }

            SelectHandler handler = new SelectHandler() {

                @Override
                public void onSelect(SelectEvent event) {
                    TextButton btn = (TextButton) event.getSource();
                    String txt = btn.getText();
                    if (txt.equals("Expand")) {
                        con.expand(r);
                    } else if (txt.equals("Collapse")) {
                        con.collapse(r);
                    } else if (txt.equals("Show")) {
                        con.show(r);
                    } else {
                        con.hide(r);
                    }
                }
            };
        }

        return widget;
    }

    public void onModuleLoad() {
        Viewport viewport = new Viewport();
        viewport.add(asWidget());


        RootPanel.get().add(viewport);
    }
}
